<script>
export default {
  name: "AddGoods",
  methods:{
    addGoods(){
      const addTime =Date.now();
      const productName = this.$refs.productName.value.trim();
      const productPrice = this.$refs.productPrice.value.trim();
      const productStock = this.$refs.productStock.value.trim();
      if(productName && productPrice && productStock){
        this.$store.commit('ADD_GOODS',{
          id:Math.random().toString(36).slice(2),
          productName,
          productPrice,
          productStock,
          addTime
        })
        this.$router.push('/goodslist');
      }else {
        alert('请正确添加商品')
      }
    }
  }
}
</script>

<template>
<div>
  <form>
    <div>
      <span>商品名称</span> :
      <input ref="productName" type="text" placeholder="请输入商品名称">
    </div>

    <div>
      <span>商品价格</span> :
      <input ref="productPrice" type="number" >
      <span>元</span>
    </div>

    <div>
      <span>库存数量</span> :
      <input ref="productStock" type="number">
    </div>

    <button @click="addGoods" >添加商品</button>
  </form>
</div>
</template>

<style scoped>

</style>
